home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_3.lha
/
7_3
/
7_3d.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
1KB
|
54 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ exercise 7.3
/ draw a circle
/ draw a point, offset by the location
/ of the center of the circle
nline void put_circle_point(int x, int y, point center)
put_point(x + center.x, y + center.y);
/ draw the point in all 8 octants
tatic void draw_circle_points(point pt, point center)
put_circle_point(pt.x, pt.y, center);
put_circle_point(pt.y, pt.x, center);
put_circle_point(pt.y, -pt.x, center);
put_circle_point(pt.x, -pt.y, center);
put_circle_point(-pt.x, -pt.y, center);
put_circle_point(-pt.y, -pt.x, center);
put_circle_point(-pt.y, pt.x, center);
put_circle_point(-pt.x, pt.y, center);
/ draw a circle using Bresenham's algorithm
/ as described by Foley and Van Dam, 1982
oid circle:: draw()
point pt(0, radius);
int d = 3 - 2 * radius;
while (pt.x < pt.y)
{
draw_circle_points(pt, center);
if (d < 0)
d += 4 * pt.x + 6;
else
{
d += 4 * (pt.x - pt.y) + 10;
pt.y--;
}
pt.x++;
}
if (pt.x == pt.y)
draw_circle_points(pt, center);